package com.ssy.lingxi.message.entity;


import com.ssy.lingxi.message.handler.convert.JpaJsonToMapConverter;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Map;

/**
 * IM聊天记录 - DO
 * @author fhj
 * @date 2021/03/29
 * @version 2.0.0
 */
@Data
@Entity
@Table(schema = "public", name = "msg_im_chat_record")
public class ImChatRecordDO implements Serializable {

    private static final long serialVersionUID = 6926401889729333675L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "im_chat_record_seq")
    @SequenceGenerator(sequenceName = "msg_im_chat_record_seq", name = "im_chat_record_seq", allocationSize = 1)
    @ApiModelProperty(value = "ID")
    private Long id;

    @Column(columnDefinition = "varchar(128)")
    @ApiModelProperty(value = "发送者ID")
    private String fromAccount;

    @Column(columnDefinition = "varchar(128)")
    @ApiModelProperty(value = "接收者ID")
    private String toAccount;

    @Column(columnDefinition = "int8")
    @ApiModelProperty(value = "发送者会员ID")
    private String fromMemberId;

    @Column(columnDefinition = "int8")
    @ApiModelProperty(value = "接收者会员ID")
    private String toMemberId;

    @Column(columnDefinition = "int8")
    @ApiModelProperty(value = "消息时间")
    private Long msgTime;

    @Column(columnDefinition = "varchar(256)")
    @ApiModelProperty(value = "消息的唯一标识")
    private String msgKey;

    @Column(columnDefinition = "int2")
    @ApiModelProperty(value = "消息结果（0成功；非0失败；）")
    private Integer sendMsgResult;

    @Column(columnDefinition = "varchar(128)")
    @ApiModelProperty(value = "失败原因")
    private String errorInfo;

    @Column(columnDefinition = "int4")
    @ApiModelProperty(value = "未读的单聊消息总数量")
    private Integer unreadMsgNum;

    @Convert(converter = JpaJsonToMapConverter.class)
    @Column(columnDefinition = "jsonb")
    @ApiModelProperty(value = "消息体")
    private Map<String, Object> msgBody;

    @Column(columnDefinition = "int8")
    @ApiModelProperty(value = "创建时间")
    private Long createTime = System.currentTimeMillis();
}
